*&---------------------------------------------------------------------*
*& Report  ZALVGRID_01
*&
*&---------------------------------------------------------------------*

report  zalvgrid_01.

data: gr_container type ref to cl_gui_custom_container.
data: gr_alvgrid   type ref to cl_gui_alv_grid.

* 使用OK_CODE，在Screen和Program之间交换数据
data: ok_code like sy-ucomm,
      save_ok like sy-ucomm.

data: gt_spfli type standard table of spfli.

start-of-selection.
  perform get_data.
  call screen 100.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
form get_data.
  select * into table gt_spfli from spfli.
endform.                    "get_data


* 初始化container和ALV grid
form init_components.
  create object gr_container
    exporting
      container_name              = 'CONTAINER1'.

  create object gr_alvgrid
    exporting
      i_parent          = gr_container .
endform.                    "init_components


* Show data in ALV
form alv_show.
  call method gr_alvgrid->set_table_for_first_display
    exporting
      i_structure_name = 'SPFLI'
    changing
      it_outtab        = gt_spfli[].

endform.                    "alv_show

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
module status_0100 output.
  perform init_components.
  perform alv_show.

  set pf-status 'Z100'.
endmodule.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
module user_command_0100 input.
  save_ok = ok_code.
  clear ok_code.

  if save_ok = '&EXIT'.
    leave program.
  endif.
endmodule.                 " USER_COMMAND_0100  INPUT